﻿using FirstFloor.ModernUI.Presentation;
using FirstFloor.ModernUI.Windows.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Input;

namespace EasyInvoice.WPF.ViewModel
{
    class SettingsExportViewModel : NotifyPropertyChanged
    {
        private string exportFolderLocation  = EasyInvoice.WPF.Properties.Settings.Default.ExportFolderLocation;

        public string ExporFolderLocation
        {
            get { 
                return this.exportFolderLocation;
            }
            set {
                if (this.exportFolderLocation != value)
                { this.exportFolderLocation = value;
                OnPropertyChanged("ExporFolderLocation");

                }

            }

        }

        //for opening up the Add Client window
        private ICommand showBrowseCommand;

        public ICommand ShowBrowseCommand
        {
            get
            {
                if (showBrowseCommand == null)
                {
                    showBrowseCommand = new Common.CommandBase(
                        i => this.BrowseFolders(),
                        null);
                }
                return showBrowseCommand;
            }
        }
        private ICommand showSaveCommand;

        public ICommand ShowSaveCommand
        {
            get
            {
                if (showSaveCommand == null)
                {
                    showSaveCommand = new Common.CommandBase(
                        i => this.SaveSettings(),
                        i=> (Properties.Settings.Default.ExportFolderLocation != this.exportFolderLocation));
                }
                return showSaveCommand;
            }
        }

        private void SaveSettings()
        {
            EasyInvoice.WPF.Properties.Settings.Default.ExportFolderLocation = this.exportFolderLocation;
            Properties.Settings.Default.Save();
        }

        private void BrowseFolders()
        {

            EasyInvoice.WPF.Common.BrowseFolders folderBrowser = new EasyInvoice.WPF.Common.BrowseFolders
            {
                Title = "Browse For Folder",
                SelectedPath = EasyInvoice.WPF.Properties.Settings.Default.ExportFolderLocation,
                Description = "select folder where invoices will be databaseed:",
            };
           //folderBrowser.Buttons = new System.Windows.Controls.Button[] { folderBrowser.OkButton, folderBrowser.CancelButton };
            if (folderBrowser.ShowDialog() == true)
                ExporFolderLocation = folderBrowser.SelectedPath;

            this.OnPropertyChanged("ExporFolderLocation");
        }
        
    }
}
